clear all
set more off
* set directory 

********************************************************************************
* FIGURE 2 --- CS EVENT STUDY

use matched_analysis_file,clear

* sample restrictions
drop if match_units_flag==1
keep if never_ward==1 | ever_treated==1
drop if pop_flag==1
su mean_units_pc, det
drop if mean_units_pc > `r(p95)'

* switch to two-year bin to improve figure legibility
replace treatment_year=0 if treatment_year==.
gen alt_year = year
replace alt_year=floor(alt_year/2)
tab alt_year
gen alt_treatment_year=floor(treatment_year/2)
collapse (mean) pc_* (first) state_year statefips alt_treatment_year *80 ,by(id alt_year)

* create main figure
csdid pc_all statefips pop80 pct_white80 pct_owned80 median_hh_income80, ivar(id) time(alt_year) gvar(alt_treatment_year) cluster(statefips)
estat event, wboot rseed(1) window(-4 4)
csdid_plot, xtitle(Years to Reform) name(g1) legend(off) 
addplot g1: , xlabel(-4 "-8+" -3 "-6" -2 "-4" -1 "-2" 0 "0" 1 "2" 2 "4" 3 "6" 4 "8+") legend(off) ytitle(Average Treatment on the Treated)
